package com.greatmay.util;

import java.util.Map;

public class ConfigHolder {
    public static final String BOOK_BASEDIR = "book.basedir";
    public static final String BOOK_BASEURL = "book.baseurl";
    public static final String VIDEO_BASEDIR = "video.basedir";
    public static final String VIDEO_BASEURL = "video.baseurl";
    public static final String PIC_BASEDIR = "pic.basedir";
    public static final String PIC_BASEURL = "pic.baseurl";
    public static final String OTHERS_BASEDIR = "other.basedir";
    public static final String OTHERS_BASEURL = "other.baseurl";
    private Map<String, Object> config;
    private ConfigHolder() {
    }
    private static class SingletonHolder {
        public static final ConfigHolder INSTANCE = new ConfigHolder();
    }

    public static ConfigHolder getConfigHolder() {
        return SingletonHolder.INSTANCE;
    }

    public synchronized void configure(Map<String, Object> config) {
        if (config == null) {
            throw new IllegalArgumentException();
        }
        this.config = config;
    }

    public String getConfigString(String key) {
        Object value = config.get(key);
        return value == null ? null : value.toString();
    }

    public Object getConfigObject(String key) {
        return config.get(key);
    }
}
